<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./css/animate.css">
    <script src="./js/vue.js"></script>
    <style>
        #app {
            border: 2px solid black;
            padding: 10px;
            margin-bottom: 400px;
        }

        .child1 {
            margin: 20px;
            padding: 10px;
            background-color: #cccccc;
            position: absolute;
            width: 80%;
        }

        .child2 {
            margin: 20px;
            padding: 10px;
            background-color: brown;
            width: 80%;
            position: absolute;

        }

        .begin {
            opacity: 0;
            transform: translateX(200%);
        }

        .begin1 {
            opacity: 1;
            transform: translateX(0px);
        }

        .active {
            transition: all 1s linear 0s;
        }

        .end {
            opacity: 1;
            transform: translateX(0px);
        }

        .end1 {
            opacity: 0;
            transform: translateX(-100%);
        }
    </style>
</head>

<body>
    <div id="app">
        <h3>父组件</h3>
        <input type="button" value="显示|隐藏" @click="flag=!flag">
        <input type="button" value="显示1" @click=" name='ChildOne' ">
        <input type="button" value="显示2" @click=" name='ChildTwo' ">
        <!-- <transition enter-class="begin" enter-active-class="active" enter-to-class="end"
                    leave-class="begin1" leave-active-class="active" leave-to-class="end1">
            <div class="child1" v-if="flag">
                <h3>测试标签1</h3>
            </div>
        </transition> -->
        <!-- <transition-group enter-class="begin" enter-active-class="active" enter-to-class="end"
                        leave-class="begin1" leave-active-class="active" leave-to-class="end1">
            <div class="child1" v-show="flag" key="1">
                <h3>测试标签1</h3>
            </div>
            <div class="child2" v-show="!flag" key="2">
                <h3>测试标签2</h3>
            </div>
        </transition-group> -->
        <!-- <transition enter-class="begin" enter-active-class="active" enter-to-class="end" leave-class="begin1"
            leave-active-class="active" leave-to-class="end1">
            <keep-alive>
                <component :is="name"></component>
            </keep-alive>

        </transition> -->
        <transition enter-active-class="animated fadeInRight" leave-active-class="animated fadeOutLeft">
            <keep-alive>
                <component :is="name"></component>
            </keep-alive>

        </transition>
    </div>

    <template id="ChildOne">
        <div class="child1" id="组件One">
            <h3>子组件one</h3>
        </div>
    </template>

    <template id="ChildTwo">
        <div class="child2" id="组件Two">
            <h3>子组件two</h3>
        </div>
    </template>
</body>
<script>
    Vue.component("ChildOne", {
        template: "#ChildOne",
    });
    Vue.component("ChildTwo", {
        template: "#ChildTwo",

    });

    // 动态组件实在 固定的vue实例的容器中，进行动态化的组件切换
    new Vue({
        el: "#app",
        data: {
            flag: true,
            name: "ChildOne"
        }
    });

</script>

</html>